package com.studiocode.aspeaker;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract.PhoneLookup;

public class ContactsUtils {
	
	public String NameFromNumber(Context context, String number)
	{
        // Get the base URI
        Uri myPerson = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, number);

        // Column to return
        String[] projection = new String[] { PhoneLookup._ID, PhoneLookup.NUMBER, PhoneLookup.DISPLAY_NAME };
        Cursor cursor = context.getContentResolver().query(myPerson, projection, 
        		null, null, null);

        if (cursor.moveToFirst())
        {
            int  idColumn = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
            String id = cursor.getString(idColumn);

            cursor.close();

            return id;
        }

        cursor.close();

        return number;
    }
	
}

